<?php
/*
  $Program: ECJC Online Shop
  $Id: account.php
  $Based on: osCommerce, Open Source E-Commerce Solutions
  Released under the GNU General Public License
*/

$optionec = 'com_oscommerce';
  define('_OSCOMMERCE_LOADED', 1);
  define('PAGE_PARSE_START_TIME', microtime());
  define('PROJECT_VERSION', 'osCommerce 2.2RC1a');
  define('MOSCOM_VERSION',  'ECJC V1.2.1RC1');

  error_reporting(E_ALL & ~E_NOTICE);
// Set the local configuration parameters - mainly for developers
  if (file_exists('components/'.$optionec.'/includes/local/configure.php'))
    include('components/'.$optionec.'/includes/local/configure.php');
// include server parameters
  require('components/'.$optionec.'/includes/configure.php');
// define application globals
  global $navigation, $language, $lng, $languages_id;
  global $cart, $currencies, $mosUser, $request_type;
  global $breadcrumb, $catID, $mosConfig_live_site;
  global $messageStack, $order;
  
  
 // some code to solve compatibility issues
  require(DIR_WS_FUNCTIONS . 'compatibility.php');
  




  require(DIR_WS_INCLUDES . 'filenames.php');
  require(DIR_WS_INCLUDES . 'database_tables.php');
  define('BOX_WIDTH', 125); // Kept for backward compatablity, not used in reality.
  require(DIR_WS_FUNCTIONS . 'database.php');
  tep_db_connect() or die('Unable to connect to database server!');
// set the application parameters
  $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
  while ($configuration = tep_db_fetch_array($configuration_query)) {
    define($configuration['cfgKey'], $configuration['cfgValue']);
  }

  $vendor_configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_VENDOR_CONFIGURATION);
  while ($vendor_configuration = tep_db_fetch_array($vendor_configuration_query)) {
    define($vendor_configuration['cfgKey'], $vendor_configuration['cfgValue']);
  }
  
  // set the type of request (secure or not)
  $request_type = (getenv('HTTPS') == 'on') ? 'SSL' : 'NONSSL';
// set php_self in the local scope
  if (!isset($PHP_SELF)) $PHP_SELF = $_SERVER['PHP_SELF'];
//This should be removed...V1.1.71 ???
  if ($request_type == 'NONSSL') {
    define('DIR_WS_CATALOG', DIR_WS_HTTP_CATALOG);
  } else {
    define('DIR_WS_CATALOG', DIR_WS_HTTPS_CATALOG);
  }

 if ($_REQUEST['option'] == 'com_oscommerce'){
$mainframe->setPageTitle( STORE_NAME);
}
// set the HTTP GET parameters manually if search_engine_friendly_urls is enabled
  if (SEARCH_ENGINE_FRIENDLY_URLS == 'true') {
    if (strlen(getenv('PATH_INFO')) > 1) {
      $GET_array = array();
      $PHP_SELF = str_replace(getenv('PATH_INFO'), '', $PHP_SELF);
      $vars = explode('/', substr(getenv('PATH_INFO'), 1));
      for ($i=0, $n=sizeof($vars); $i<$n; $i++) {
        if (strpos($vars[$i], '[]')) {
          $GET_array[substr($vars[$i], 0, -2)][] = $vars[$i+1];
        } else {
          $_REQUEST[$vars[$i]] = $vars[$i+1];
        }
        $i++;
      }

      if (sizeof($GET_array) > 0) {
        while (list($key, $value) = each($GET_array)) {
          $_REQUEST[$key] = $value;
        }
      }
    }
  }
// define general functions used application-wide
  require(DIR_WS_FUNCTIONS . 'general.php');
  require(DIR_WS_FUNCTIONS . 'html_output.php');
  require(DIR_WS_FUNCTIONS . 'subscription.php');
// set the cookie domain
  $cookie_domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
  $cookie_path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);
// include cache functions if enabled
  if (USE_CACHE == 'true') include(DIR_WS_FUNCTIONS . 'cache.php');
// include shopping cart class

if(!class_exists( 'JConfig' ) ) {
  require(DIR_WS_CLASSES . 'shopping_cart.php');
//}
// include navigation history class
  require(DIR_WS_CLASSES . 'navigation_history.php');

  }

  require(DIR_WS_FUNCTIONS . 'sessions.php');
  tep_session_start();
  $session_started=true;

// set the session name and save path
 //  tep_session_name('ecjcID');
  tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
   if (function_exists('session_set_cookie_params')) {
//    session_set_cookie_params(0, $cookie_path, $cookie_domain);
    session_set_cookie_params(0, '/');
  } elseif (function_exists('ini_set')) {
    ini_set('session.cookie_lifetime', '0');
    ini_set('session.cookie_path', $cookie_path);
    ini_set('session.cookie_domain', $cookie_domain);
  }

  tep_session_id(session_id());

  if (!tep_session_is_registered('cart') || !is_object($cart)) {

    tep_session_register('cart');
    $cart = new shoppingCart;
  }

// Create the WISHLIST
  if (!is_object($wishlist)) {

    tep_session_register('wishlist');
    $wishlist = new wishlist_class;
  }
// include currencies class and create an instance
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();
  
  require(DIR_WS_CLASSES . 'PriceFormatter.php');
  $pf = new PriceFormatter;

  require(DIR_WS_CLASSES . 'PriceFormatterStore.php');
  $pfs = new PriceFormatterStore;

// include the mail classes
  require(DIR_WS_CLASSES . 'mime.php');
  require(DIR_WS_CLASSES . 'email.php');

// set the language
// joomlafish compatablity :::::
$jflang = isset($_REQUEST['lang'])?$_REQUEST['lang']:'';
if($jflang != ''){
global $database;
$database->setQuery("Select code from #__osc_languages where directory = '$jflang'");
$jflcod = $database->loadResult();
//echo $jflcod;

}


  if (!tep_session_is_registered('language') || isset($_REQUEST['language']) || $jflcod != '') {
    if (!tep_session_is_registered('language')) {
      tep_session_register('language');
      tep_session_register('languages_id');
    }

    include(DIR_WS_CLASSES . 'language.php');
    $lng = new language();

    if (isset($_REQUEST['language']) && tep_not_null($_REQUEST['language'])) {
      $lng->set_language($_REQUEST['language']);
      }elseif($jflcod != ''){
      $lng->set_language($jflcod);
      
    } else {
      $lng->get_browser_language();
    }

    $language = $lng->language['directory'];
    $languages_id = $lng->language['id'];
  }
  // work around for langauges as a global problem
if ($language == NULL){
//$get_language_query = tep_db_query('select * from ' . TABLE_LANGUAGES .' where `sort_order` = "1"');
$get_language_query = tep_db_query("select configuration_value from ".TABLE_CONFIGURATION." where configuration_key = '".DEFAULT_LANGUAGE."'");
$get_language_query2 = tep_db_fetch_array($get_language_query);
$langcode = $get_language_query2['configuration_key'];
$get_language_query3 = tep_db_query('select * from ' . TABLE_LANGUAGES .' where `code` = "'.$langcode.'"');
$get_language_query4 = tep_db_fetch_array($get_language_query3);
$language = $get_language_query4['directory'];

$languages_id = $get_language_query4['languages_id'];
  }

// include the language translations
  require(DIR_WS_LANGUAGES . $language . '.php');

// currency
  if (!tep_session_is_registered('currency') || isset($_REQUEST['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
    if (!tep_session_is_registered('currency')) tep_session_register('currency');


	  if (isset($_GET['currency']) && $currencies->is_set($_GET['currency'])) {
	    $currency = $_GET['currency'];
    } else {
      $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
    }
  }
//print_r($navigation);
//moved
// navigation history
if($_REQUEST['osMod'] != ' product_thumb'){
  if (tep_session_is_registered('navigation')) {
    if (PHP_VERSION < 4) {
      $broken_navigation = $navigation;
      $navigation = new navigationHistory;
      $navigation->unserialize($broken_navigation);
    }
  } else {
    tep_session_register('navigation');
    $navigation = new navigationHistory;
  }
  //V1.1.7 Fix to navigation issue.
//  if ($_REQUEST['option'] == 'com_oscommerce'){
  $broken_navigation = $navigation;
      $navigation = new navigationHistory;
      $navigation->unserialize($broken_navigation);
  
  $navigation->add_current_page();
  //$navigation->set_snapshot();
  //}
  //print_r($navigation);
  }
  
  if(!class_exists( 'JConfig' ) ) {
  
  require(DIR_WS_FUNCTIONS . 'user_account.php');
  }else{
  require(DIR_WS_FUNCTIONS . 'user_accountj15.php');
  }


  ecjc_load_credentials();


global $my;
//print_r($my);
  if (tep_session_is_registered('customer_id') && !$my->id) {
    tep_session_unregister('customer_id');
    tep_session_unregister('customer_default_address_id');
    tep_session_unregister('customer_first_name');
    tep_session_unregister('customer_country_id');
    tep_session_unregister('customer_zone_id');
    tep_session_unregister('comments');
	tep_session_unregister('gv_id');// CCGV
	tep_session_unregister('sppc_customer_group_id');
	tep_session_unregister('sppc_customer_group_show_tax');
	tep_session_unregister('sppc_customer_group_tax_exempt');
  }

// BOF: Down for Maintenance except for admin ip
if (EXCLUDE_ADMIN_IP_FOR_MAINTENANCE != getenv('REMOTE_ADDR')){
	if ($_REQUEST['option'] == 'com_oscommerce'){
	if (DOWN_FOR_MAINTENANCE=='true' and $_REQUEST['osMod'] != 'down_for_maintenance') { tep_redirect(tep_href_link(DOWN_FOR_MAINTENANCE_FILENAME)); }
	}
	}
// do not let people get to down for maintenance page if not turned on
if (DOWN_FOR_MAINTENANCE=='false' and strstr($PHP_SELF,DOWN_FOR_MAINTENANCE_FILENAME)) {
    tep_redirect(tep_href_link(FILENAME_DEFAULT));
}
// EOF: WebMakers.com Added: Down for Maintenance

 if(!tep_session_is_registered('sppc_customer_group_id')) { 
  $customer_group_id = '0';
  } else {
   $customer_group_id = $sppc_customer_group_id;
  }
  
//echo 'session<pre>' . print_r($_SESSION, true) . '</pre>';

// Shopping cart actions
  if (isset($_REQUEST['action'])) {
    // redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
    if ($session_started == false) {
      tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
    }
     $hide_product = false;
    
      if (isset($_POST['products_id']) && !is_array($_POST['products_id'])) {
	      $pid_for_hide = (int)$_POST['products_id'];
      } elseif (isset($_GET['products_id'])) {
	      $pid_for_hide = (int)$_GET['products_id'];
      } elseif (isset($_GET['pid'])) {
	      $pid_for_hide = (int)$_GET['pid'];
		  } elseif (isset($_GET['notify']) && !is_array($_GET['notify'])) {
	      $pid_for_hide = (int)$_GET['notify'];
			} elseif (isset($_POST['notify']) && !is_array($_POST['notify'])) {
				$pid_for_hide = (int)$_POST['notify'];
			}
    if (tep_not_null($pid_for_hide)) {
		//	$hide_product = tep_get_hide_status_single($customer_group_id, $pid_for_hide);
    } else {
			$hide_product = false;
		} // end if/else (tep_not_null($pid_for_hide))
  
		$temp_post_get_array = array();
		$hide_status_products = array();
    if (is_array($_POST['products_id']) && tep_not_null($_POST['products_id']) && tep_not_null($_POST['products_id'][0])) {
			$temp_post_get_array = $_POST['products_id'];
			$hide_status_products = tep_get_hide_status($hide_status_products, $customer_group_id, $temp_post_get_array);
		} 
		  if (is_array($_GET['products_id']) && tep_not_null($_GET['products_id']) && tep_not_null($_GET['products_id'][0])) {
			$temp_post_get_array = $_GET['products_id'];
			$hide_status_products = tep_get_hide_status($hide_status_products, $customer_group_id, $temp_post_get_array);
		}
		if (is_array($_POST['notify']) && tep_not_null($_POST['notify']) && tep_not_null($_POST['notify'][0])) {
			$temp_post_get_array = $_POST['notify'];
			$hide_status_products = tep_get_hide_status($hide_status_products, $customer_group_id, $temp_post_get_array);
		} 
		if (is_array($_GET['notify']) && tep_not_null($_GET['notify']) && tep_not_null($_GET['notify'][0])) {
			$temp_post_get_array = $_GET['notify'];
			$hide_status_products = tep_get_hide_status($hide_status_products, $customer_group_id, $temp_post_get_array);
		} 		
			
    if (!$hide_product) { // product does not need to be hidden from the customer group
// EOF Separate Pricing Per Customer v4.1, Hide products from groups mod
$togo = '';
    if (DISPLAY_CART == 'true') {
      $goto =  FILENAME_SHOPPING_CART;
      $parameters = array('action', 'catID', 'products_id', 'pid');
    } else {
      $goto = modSefRef();
      if ($_REQUEST['action'] == 'buy_now') {
        $parameters = array('action', 'pid', 'products_id');
      } else {
        $parameters = array('action', 'pid');
        $togo = '&products_id=' . $_POST['products_id'];
      }
    }
    $goto = tep_href_link($goto);
    $goto = str_replace('&amp;', '&', $goto);
    $goto .= "&Itemid=" . $_REQUEST['Itemid'];
    $goto .= $togo;

    switch ($_REQUEST['action']) {
      // customer wants to update the product quantity in their shopping cart
      case 'update_product' : for ($i=0, $n=sizeof($_REQUEST['products_id']); $i<$n; $i++) {
                                if (in_array($_REQUEST['products_id'][$i], (is_array($_REQUEST['cart_delete']) ? $_REQUEST['cart_delete'] : array()))) {
                                  $cart->remove($_REQUEST['products_id'][$i]);
                                } else {
                                  if (PHP_VERSION < 4) {
                                    // if PHP3, make correction for lack of multidimensional array.
                                    reset($_REQUEST);
                                    while (list($key, $value) = each($_REQUEST)) {
                                      if (is_array($value)) {
                                        while (list($key2, $value2) = each($value)) {
                                          if (ereg ("(.*)\]\[(.*)", $key2, $var)) {
                                            $id2[$var[1]][$var[2]] = $value2;
                                          }
                                        }
                                      }
                                    }
                                    $attributes = ($id2[$_REQUEST['products_id'][$i]]) ? $id2[$_REQUEST['products_id'][$i]] : '';
                                  } else {
                                    $attributes = ($_REQUEST['id'][$_REQUEST['products_id'][$i]]) ? $_REQUEST['id'][$_REQUEST['products_id'][$i]] : '';
                                  }
                                  //$cart->add_cart($_REQUEST['products_id'][$i], $_REQUEST['cart_quantity'][$i], $attributes, false);
                                  // BOF SPPC, Hide products and categories from groups
																	foreach($hide_status_products as $key => $subarray) {
																	  if ($subarray['products_id'] == tep_get_prid($_POST['products_id'][$i]) && $subarray['hidden'] == '0') {
                                  $cart->add_cart($_POST['products_id'][$i], $_POST['cart_quantity'][$i], $attributes, false);
																		}
																	} // end foreach($hide_status_products as $key => $subarray)
			// EOF SPPC, Hide products and categories from groups
                                }
                              }
                              tep_redirect($goto);
                              break;
      // customer adds a product from the products page
      case 'add_product' :    

      
      if (isset($_REQUEST['products_id']) && is_numeric($_REQUEST['products_id'])) {
      
      $auction_price = tep_get_products_auction_price($_REQUEST['products_id']);
      if($auction_price) {
      //auction product, lets redirect to auction page
      tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO,'products_id='.$_REQUEST['products_id']));
      
      }
                                $cart->add_cart($_REQUEST['products_id'], $cart->get_quantity(tep_get_uprid($_REQUEST['products_id'], $_REQUEST['id']))+(int)$_POST['quantity'], $_REQUEST['id']);
                              }
                           //   die(tep_href_link($goto));
                              tep_redirect($goto);
                              break;
                              //bof product listing with attributes
	    case 'buy_now_form' : 
	    $auction_price = tep_get_products_auction_price($_REQUEST['products_id']);
      if($auction_price) {
      //auction product, lets redirect to auction page
      tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO,'products_id='.$_REQUEST['products_id']));
      }
							if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
                           $prodId = (int)$_POST['products_id'];
                           $cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($_POST['products_id'], $_POST["id_$prodId"]))+($_POST['cart_quantity']), $_POST["id_$prodId"]);
                               }
                        // tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                        tep_redirect($goto . '&' . tep_get_all_get_params($parameters));
                           break;
      // customer adds multiple products from the products_listing page
      case 'add_multiple' :    
      
                              while ( list( $key, $val ) = each( $_POST ) ) 
                                 { 
                                 if (substr($key,0,11) == "Qty_ProdId_" || substr($key,0,11) == "Qty_NPrdId_") 
                                 { 
                                 $prodId = substr($key, 11); 
                                 $qty = $val; 
                                 if ($qty <= 0 ) continue; 
                                 if(isset($_POST["id_$prodId"]) && is_array($_POST["id_$prodId"])) {
                                   // We have attributes
                                   $cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId,$_POST["id_$prodId"]))+$qty, $_POST["id_$prodId"]);
                                 } else {
                                   // No attributes
                                   $cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
                                 }
                                } 
                              } 
                             // tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                             tep_redirect($goto . '&' . tep_get_all_get_params($parameters));
                              break;
							  //eof product listing with attributes
                              
      // performed by the 'buy now' button in product listings and review page
      case 'buy_now' :       

      
       if (isset($_REQUEST['products_id'])) {
       $auction_price = tep_get_products_auction_price($_REQUEST['products_id']);
       
      if($auction_price) {
      //auction product, lets redirect to auction page
      tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO,'products_id='.$_REQUEST['products_id']));
      }
                                if (tep_has_product_attributes($_REQUEST['products_id'])) {
                                  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $_REQUEST['products_id']));
                                } else {
                                 // $cart->add_cart($_REQUEST['products_id'], $cart->get_quantity($_REQUEST['products_id'])+1);
                                 $cart->add_cart($_REQUEST['products_id'], $cart->get_quantity(tep_get_uprid($_REQUEST['products_id'], $_REQUEST['id']))+1, $_REQUEST['id']);
                                }
                              }
                              tep_redirect($goto);
                              break;
      case 'notify' :         if (tep_session_is_registered('customer_id')) {
                                if (isset($_REQUEST['products_id'])) {
                                  $notify = $_REQUEST['products_id'];
                                } elseif (isset($_REQUEST['notify'])) {
                                  $notify = $_REQUEST['notify'];
                                } elseif (isset($_REQUEST['notify'])) {
                                  $notify = $_REQUEST['notify'];
                                } else {
                                  tep_redirect(tep_href_link(modSefRef(), tep_get_all_get_params(array('action', 'notify'))));
                                }
                                if (!is_array($notify)) $notify = array($notify);
                                for ($i=0, $n=sizeof($notify); $i<$n; $i++) {
                                  $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $notify[$i] . "' and customers_id = '" . $customer_id . "'");
                                  $check = tep_db_fetch_array($check_query);
                          
                                  // BOF SPPC, Hide products and categories from groups
		if (is_array($hide_status_products) && tep_not_null($hide_status_products)) {
																	foreach($hide_status_products as $key => $subarray) {
																	  if ($subarray['products_id'] == tep_get_prid($notify[$i]) && $subarray['hidden'] == '0') {
                                    if ($check['count'] < 1) {
                                    tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . $notify[$i] . "', '" . $customer_id . "', now())");
                                    }
																	 } // end if ($subarray['products_id'] == tep_get_prid($notify[$i])...
																	} // end foreach ($hide_status_products as $key => $subarray)
		} else {
			                              if ($check['count'] < 1) {
                                    tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . $notify[$i] . "', '" . $customer_id . "', now())");
                                    }
		}
		// EOF SPPC, Hide products and categories from groups
                                }
                                tep_redirect(tep_href_link(modSefRef(), tep_get_all_get_params(array('action', 'notify'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
      case 'notify_remove' :  if (tep_session_is_registered('customer_id') && isset($_REQUEST['products_id'])) {
                                $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $_REQUEST['products_id'] . "' and customers_id = '" . $customer_id . "'");
                                $check = tep_db_fetch_array($check_query);
                                if ($check['count'] > 0) {
                                  tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $_REQUEST['products_id'] . "' and customers_id = '" . $customer_id . "'");
                                }
                                tep_redirect(tep_href_link(modSefRef(), tep_get_all_get_params(array('action'))));
                              } else {
                                $navigation->set_snapshot();
                                tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
                              }
                              break;
                      
                      
      case 'cust_order' :    
if (isset($_REQUEST['pid'])) 
 {

///////////////////////////////
     $cart->add_cart($_REQUEST['pid'], $cart->get_quantity($_REQUEST['pid'])+1);
//////////////////////////////								
// remove here from wishlist								
	$wishlist->remove($_REQUEST['pid']);  
 //       $cart->add_cart($_REQUEST['pid'], $cart->get_quantity($_REQUEST['pid'])+1);

}
                              tep_redirect(tep_href_link(FILENAME_WISHLIST));
                              break;

// Add product to the wishlist

case 'add_wishlist' :  if (ereg('^[0-9]+$', $_REQUEST['products_id'])) {
                      $wishlist->add_cart($_REQUEST['products_id'], 
 $wishlist->get_quantity(tep_get_uprid($_REQUEST['products_id'], $_REQUEST['id']))+1, $_REQUEST['id']);
 $cart->remove($_REQUEST['pid']); 
				}
				 
tep_redirect(tep_href_link(FILENAME_WISHLIST, '', 'NONSSL'));
                              break;
// Add wishlist item to the cart
case 'wishlist_add_cart':     tep_redirect(tep_href_link(FILENAME_WISHLIST));
                              break;


// remove item from the wishlist
///// CHANGES TO case 'remove_wishlist' BY DREAMSCAPE /////
      case 'remove_wishlist' :
                             $wishlist->remove($_REQUEST['pid']);  
                            tep_redirect(tep_href_link(FILENAME_WISHLIST),'','NONSSL');
                             break;
//End Wishlist 2.0.1 Modification
case 'add_wishlist_from_cart' :
if (isset($_REQUEST['pid'])) 
 {

///////////////////////////////
   $cart->remove($_REQUEST['pid']);  
//////////////////////////////								
	$wishlist->add_cart($_REQUEST['pid'], 
 $wishlist->get_quantity(tep_get_uprid($_REQUEST['pid'], $_REQUEST['id']))+1, $_REQUEST['id']);
 //       $cart->add_cart($_REQUEST['pid'], $cart->get_quantity($_REQUEST['pid'])+1);

}
break;
/*
    }
  }
*/
    } // end switch
// BOF Separate Pricing Per Customer v4.1, Hide products from groups mod
    } else { // $hide_product is true
	    tep_redirect(tep_href_link(FILENAME_DEFAULT));
    }
// EOF Separate Pricing Per Customer v4.1, Hide products from groups mod
  } // if (isset($HTTP_GET_VARS['action']))
// include the who's online functions

  require(DIR_WS_FUNCTIONS . 'whos_online.php');
  tep_update_whos_online();

// include the password crypto functions
  require(DIR_WS_FUNCTIONS . 'password_funcs.php');

// include validation functions (right now only email address)
  require(DIR_WS_FUNCTIONS . 'validations.php');

// split-page-results
  require(DIR_WS_CLASSES . 'split_page_results.php');

// infobox
  require(DIR_WS_CLASSES . 'boxes.php');

// auto activate and expire banners
  require(DIR_WS_FUNCTIONS . 'banner.php');
  tep_activate_banners();
  tep_expire_banners();

// auto expire special products
  require(DIR_WS_FUNCTIONS . 'specials.php');
  tep_expire_specials();

// Points/Rewards Module V1.60
require(DIR_WS_FUNCTIONS . 'redemptions.php');

// calculate category path
  if (isset($_REQUEST['catID'])) {
    $catID = $_REQUEST['catID'];
  }elseif (isset($_REQUEST['cPath'])){
    $catID = $_REQUEST['cPath'];
  } elseif (isset($_REQUEST['products_id']) && !isset($_REQUEST['manufacturers_id'])) {
    $catID = tep_get_product_path($_REQUEST['products_id']);
  } else {
    $catID = '';
  }

  if (tep_not_null($catID)) {
    $catID_array = tep_parse_category_path($catID);
    $catID = implode('_', $catID_array);
    $current_category_id = $catID_array[(sizeof($catID_array)-1)];
  } else {
    $current_category_id = 0;
  }

// include the breadcrumb class and start the breadcrumb trail
  require(DIR_WS_CLASSES . 'breadcrumb.php');
  //================================================================
if ( ($_REQUEST['currency']) ) {
   tep_session_register('kill_sid');
   $kill_sid=false;
  }
if (basename($_SERVER['HTTP_REFERER']) == 'allprods.php' ) $kill_sid = true;
if ( ( !tep_session_is_registered('customer_id') ) && ( $cart->count_contents()==0 ) && (!tep_session_is_registered('kill_sid') ) ) $kill_sid = true;
if ((basename($PHP_SELF) == FILENAME_LOGIN) && ($_REQUEST['action'] == 'process') ) $kill_sid = false;
if (basename($PHP_SELF) == FILENAME_CREATE_ACCOUNT_PROCESS) $kill_sid = false;
// Uncomment line bellow to disable SID Killer
 $kill_sid = false; 
//================================================================
  $breadcrumb = new breadcrumb;
  $breadcrumb->add(HEADER_TITLE_TOP, $mosConfig_live_site);
  $breadcrumb->add(HEADER_TITLE_CATALOG, tep_href_link(FILENAME_DEFAULT));


   if(!tep_session_is_registered('sppc_customer_group_id')) { 
     $customer_group_id = '0';
     } else {
      $customer_group_id = $sppc_customer_group_id;
   } 
   
  if (isset($catID_array)) {
    for ($i=0, $n=sizeof($catID_array); $i<$n; $i++) {   
      $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd left join " . TABLE_CATEGORIES . " c using(categories_id) where cd.categories_id = '" . (int)$catID_array[$i] . "' and language_id = '" . (int)$languages_id . "' and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0");
// EOF SPPC hide categories from groups
      if (tep_db_num_rows($categories_query) > 0) {
        $categories = tep_db_fetch_array($categories_query);
        $breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'catID=' . implode('_', array_slice($catID_array, 0, ($i+1)))));
      } else {
        break;
      }
    }
  } elseif (isset($_REQUEST['manufacturers_id'])) {
    $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_REQUEST['manufacturers_id'] . "'");
    if (tep_db_num_rows($manufacturers_query)) {
      $manufacturers = tep_db_fetch_array($manufacturers_query);
      $breadcrumb->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $_REQUEST['manufacturers_id']));
    }
  }

// add the products model to the breadcrumb trail
  if (isset($_REQUEST['products_id'])) {

    
    $model_query = tep_db_query("select pd.products_name from " . TABLE_PRODUCTS ." p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd using(products_id) left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_id = '" . (int)$_GET['products_id'] . "' and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0");
// EOF SPPC hide categories from groups
    if (tep_db_num_rows($model_query)) {
      $model = tep_db_fetch_array($model_query);
      $breadcrumb->add($model['products_name'], tep_href_link(FILENAME_PRODUCT_INFO, 'catID=' . $catID . '&products_id=' . $_REQUEST['products_id']));
    }
  }

// initialize the message stack for output messages
  require(DIR_WS_CLASSES . 'message_stack.php');
  $messageStack = new messageStack;
  
  require(DIR_WS_CLASSES . 'ProductsInCategory.php');
$pic = new ProductsInCategory;

// set which precautions should be checked
  define('WARN_INSTALL_EXISTENCE', 'true');
  define('WARN_CONFIG_WRITEABLE', 'true');
  define('WARN_SESSION_DIRECTORY_NOT_WRITEABLE', 'true');
  define('WARN_SESSION_AUTO_START', 'true');
  define('WARN_DOWNLOAD_DIRECTORY_NOT_READABLE', 'true');
 require(DIR_WS_INCLUDES . 'add_ccgvdc_application_top.php');  // CCGV
  // include theme
  $query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key ='THEME_CURRENT_CONFIG'");
  $res = tep_db_fetch_array($query);
  require(DIR_WS_MODULES . $res['configuration_value']);
  // below will be moved to database;
//define('E_TEMPLATE_FOLDER', 'default');

  // Include OSC-AFFILIATE
  require(DIR_WS_INCLUDES . 'affiliate_application_top.php');
  
  //Do the superstats business	
  if (TRACKING_USE == 'true') {
  require(DIR_WS_CLASSES . 'supertracker.php');
	$tracker = new supertracker;
	$tracker->update();
	}
	// PWA BOF
  if ($ecjc_pwa == 1 && ($osMod =='account')) tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
// PWA EOF

?>
